home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtoyc01.zip / TEST.CPP < prev    next >
C/C++ Source or Header  |  1994-01-20  |  6KB  |  273 lines

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Turbo Vision 1.0                                      */
  4. /*   TVGUID05 Demo Source File                             */
  5. /*   Copyright (c) 1991 by Borland International           */
  6. /*                                                         */
  7. /*---------------------------------------------------------*/
  8.  
  9. #define Uses_fpstream
  10. #define Uses_MsgBox
  11.  
  12. #define Uses_TApplication
  13. #define Uses_TDeskTop
  14. #define Uses_TEvent
  15. #define Uses_TEventQueue
  16. #define Uses_TKeys
  17. #define Uses_TMenuBar
  18. #define Uses_TMenuItem
  19. #define Uses_TRect
  20. #define Uses_TStatusItem
  21. #define Uses_TStatusLine
  22. #define Uses_TStatusDef
  23. #define Uses_TSubMenu
  24. #define Uses_TView
  25. #define Uses_TWindow
  26. #include <tv.h>
  27.  
  28. #include "toycfg.h"
  29. #include "modedlg.h"
  30. #include "video.h"
  31.  
  32. #include <help.h>
  33. #include "helpctx.h"
  34.  
  35. const int cmVideoMode     = 200;
  36. const int cmPreviousTopic = 201;
  37. const int cmUsingHelp     = 202;
  38. const int cmContents      = 203;
  39.  
  40.  
  41.  
  42. class TDemoApp : public TApplication
  43. {
  44.  
  45. public:
  46.     const char *helpFileName;
  47.  
  48.     TDemoApp();
  49.     static TStatusLine *initStatusLine(TRect r);
  50.     static TMenuBar *initMenuBar(TRect r);
  51.     virtual void getEvent(TEvent &event);
  52.     virtual TPalette& getPalette() const;
  53.     virtual void handleEvent(TEvent& event);
  54.     void showHelp(int aHelpCtx);
  55.     void videoMode();
  56. };
  57.  
  58. /*******************************************************
  59. class TToyApp : virtual public TApplication
  60. {
  61.  
  62. public:
  63.     const char *helpFileName;
  64.  
  65.     virtual void getEvent(TEvent &event);
  66.     virtual TPalette& getPalette() const;
  67.     void showHelp(int aHelpCtx);
  68. };
  69.  
  70. class TDemoApp : public TToyApp
  71. {
  72.  
  73. public:
  74.     TDemoApp();
  75.     static TStatusLine *initStatusLine(TRect r);
  76.     static TMenuBar *initMenuBar(TRect r);
  77.     virtual void handleEvent(TEvent& event);
  78.     void videoMode();
  79. };
  80.  
  81. ********************************************************/
  82.  
  83. #define TToyApp TDemoApp
  84.  
  85. //
  86. //  Init application
  87. //
  88.  
  89. TDemoApp::TDemoApp() :
  90.     TProgInit(TDemoApp::initStatusLine,
  91.               TDemoApp::initMenuBar,
  92.           TDemoApp::initDeskTop
  93.         )
  94. {
  95.   helpFileName = "helptest.hlp";
  96.   showHelp(hcIntro);
  97. }
  98.  
  99.  
  100. //
  101. //  Event loop to check for context help request
  102. //
  103.  
  104. void TToyApp::getEvent(TEvent &event)
  105. {
  106.   TApplication::getEvent(event);
  107.  
  108.   if (event.what==evCommand)
  109.   {
  110.     switch (event.message.command)
  111.     {
  112.       case cmHelp:          showHelp(getHelpCtx()); break;
  113.       case cmContents:      showHelp(hcContents); break;
  114.       case cmPreviousTopic: showHelp(previousTopic); break;
  115.       default:
  116.           return;
  117.     }
  118.     clearEvent(event);
  119.   }
  120. }
  121.  
  122.  
  123. //
  124. //  Return application's palette, with help colors added
  125. //
  126.  
  127. TPalette& TToyApp::getPalette() const
  128. {
  129.     static TPalette newcolor (cpColor cHelpColor, sizeof(cpColor cHelpColor)-1);
  130.     static TPalette newblackwhite(cpBlackWhite cHelpBlackWhite, sizeof(cpBlackWhite cHelpBlackWhite)-1);
  131.     static TPalette newmonochrome(cpMonochrome cHelpMonochrome, sizeof(cpMonochrome cHelpMonochrome)-1);
  132.     static TPalette *palettes[] =
  133.         {
  134.         &newcolor,
  135.         &newblackwhite,
  136.         &newmonochrome
  137.         };
  138.     return *(palettes[appPalette]);
  139. }
  140.  
  141. //
  142. //  Handle events
  143. //
  144.  
  145. void TDemoApp::handleEvent(TEvent& event)
  146. {
  147.     TApplication::handleEvent(event);
  148.     if(event.what == evCommand)
  149.     {
  150.     switch(event.message.command)
  151.         {
  152.             case cmUsingHelp:
  153.                 showHelp(hcUsingHelp);
  154.                 break;
  155.         case cmVideoMode:
  156.         videoMode();
  157.         break;
  158.         default:
  159.         return;
  160.         }
  161.     clearEvent(event);
  162.     }
  163. }
  164.  
  165.  
  166. //
  167. //  Create menu bar
  168. //
  169.  
  170. TMenuBar *TDemoApp::initMenuBar(TRect r)
  171. {
  172.  
  173.     r.b.y = r.a.y + 1;
  174.     return new TMenuBar(r,
  175.     *new TSubMenu("~V~ideo", kbAltV)+
  176.         *new TMenuItem("~V~ideo mode...", cmVideoMode, kbNoKey, hcNoContext, "")+
  177.     *new TSubMenu("~H~elp", kbAltH)+
  178.         *new TMenuItem("~C~ontents", cmContents, kbNoKey, hcNoContext, "")+
  179.         *new TMenuItem("~P~revious topic", cmPreviousTopic, kbNoKey, hcNoContext, "")+
  180.         *new TMenuItem("~U~sing help", cmUsingHelp, kbNoKey, hcNoContext, "")
  181.     );
  182. }
  183.  
  184.  
  185. //
  186. //  Create statusline
  187. //
  188.  
  189. TStatusLine *TDemoApp::initStatusLine(TRect r)
  190. {
  191.     r.a.y = r.b.y - 1;
  192.     return new TStatusLine(r,
  193.     *new TStatusDef(hcHelpOnHelp, hcHelpOnHelp)+
  194.             *new TStatusItem("~F1~ Help on Help", kbF1, cmHelp)+
  195.             *new TStatusItem("~Alt-B~ Back", kbAltB, cmPreviousTopic)+
  196.             *new TStatusItem("~Alt-C~ Contents", kbAltC, cmContents)+
  197.             *new TStatusItem("", kbF5, cmZoom)+
  198.             *new TStatusItem("", kbCtrlF5, cmResize)+
  199.     *new TStatusDef(0, 0xFFFF)+
  200.         *new TStatusItem(0, kbF10, cmMenu)+
  201.             *new TStatusItem("~F1~ Help", kbF1, cmHelp)+
  202.         *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit)
  203.     );
  204. }
  205.  
  206.  
  207. //
  208. //  Show help window
  209. //
  210.  
  211. void TToyApp::showHelp(int aHelpCtx)
  212. {
  213.   TWindow   *w;
  214.   THelpFile *hFile;
  215.   fpstream  *helpStrm;
  216.   static Boolean helpInUse = False;
  217.  
  218.   if (helpInUse == True)
  219.     message(this, evCommand, cmSwitchToTopic, (void*)aHelpCtx);
  220.   else
  221.   {
  222.     helpInUse = True;
  223.  
  224.     helpStrm = new fpstream(helpFileName, ios::in|ios::binary);
  225.     hFile = new THelpFile(*helpStrm);
  226.     if (!helpStrm)
  227.     {
  228.       messageBox("Could not open help file", mfError | mfOKButton);
  229.       delete hFile;
  230.     }
  231.     else
  232.     {
  233.       w = new THelpWindow(hFile, aHelpCtx);
  234.       w->helpCtx = hcHelpOnHelp;
  235.       if (validView(w) != 0)
  236.       {
  237.         execView(w);
  238.         destroy(w);
  239.       }
  240.     }
  241.     helpInUse = False;
  242.   }
  243. }
  244.  
  245.  
  246. //
  247. //  Determine video modes and show them in a dialog
  248. //
  249.  
  250. void TDemoApp::videoMode()
  251. {
  252.     if (messageBox("Have to do some tests, there is no guarantee that it works",
  253.                    mfInformation | mfOKButton | mfCancelButton) == cmOK)
  254.     {
  255.       TVideoList::setup();
  256.       selectVideoModeDialog();
  257.     }
  258. }
  259.  
  260.  
  261. //
  262. //  Start the whole thing
  263. //
  264.  
  265. int main()
  266. {
  267.     checkVideoType();
  268.  
  269.     TDemoApp demoApp;
  270.     demoApp.run();
  271.     return 0;
  272. }
  273.